
using Youz.Common.Entity;
using Youz.Common.Helper;
using Youz.CreditRepay.DAL;
using Youz.CreditRepay.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;

namespace Youz.CreditRepay.BLL
{
    /// <summary>
    /// Sys_Bank BLL Class
    /// </summary>
    public partial class Sys_BankBLL : BaseBLL
    {
		Sys_BankDAL dal;
		
        public Sys_BankBLL()
        {
			dal = new Sys_BankDAL();
			base.ModuleName = "Sys_Bank";
            base.MenuName = "Sys_Bank";
		}

        #region  成员方法
        /// <summary>
        ///  新增一条数据
        /// </summary>
        public bool Add(Sys_Bank model)
        {
            var r = dal.Add(model);
			
			base.WriteOperationLog(OperationType.Add, r, Core.GetJsonByObjectHaveTime(model));

            return r;
        }

        /// <summary>
        ///  保存一条数据
        /// </summary>
        public bool Update(Sys_Bank model)
        {
            var r = dal.Update(model);
			
			base.WriteOperationLog(OperationType.Update, r, Core.GetJsonByObjectHaveTime(model));

            return r;
        }

        /// <summary>
        /// 删除一条数据
        ///</summary>
        public bool Delete(Int32 ID)
        {
            var r = dal.Delete(ID);
			
			base.WriteOperationLog(OperationType.Delete, r, ID);

            return r;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Sys_Bank Get(Int32 ID)
        {
            return dal.Get(ID);
        }
		
		/// <summary>
        /// 得到一个JSON对象
        /// </summary>
        public string GetJson(Int32 ID)
        {
            return Core.GetJsonByObject(Get(ID));
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet Gets(string sqlWhere)
        {
            return dal.Gets(sqlWhere);
        }

        public string GetNameByCode(string code)
        {
            var bank = GetsByCode(code);
            return bank == null ? "" : bank.Name;
        }

        public Sys_Bank GetsByCode(string code)
        {
            var list = Gets();
            return list.Where(m => m.Code == code).FirstOrDefault();
        }

        public List<Sys_Bank> Gets()
        {
            List<Sys_Bank> list = CacheHelper.GetCache("Sys_Bank") as List<Sys_Bank>;

            if (list == null)
            {
                var ds = Gets("");
                list = new EntityHelper<Sys_Bank>().FillEntity(ds);
                CacheHelper.SetCache("Sys_Bank", list);
            }

            return list;
        }

        public List<Sys_Bank> Gets(BankCardType type)
        {
            var list = Gets();

            if (list == null || list.Count == 0)
            {
                return null;
            }

            return list.Where(m => m.Type == (int)type).ToList();
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet Gets(int top, string sqlWhere, string filedOrder)
        {
            return dal.Gets(top, sqlWhere, filedOrder);
        }
		
		/// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string sqlWhere)
        {
            return dal.GetRecordCount(sqlWhere);
        }
		
		/// <summary>
        /// 获得数据列表分页
        /// </summary>
        public DataTable Gets(string sqlWhere, int pageindex, int pagesize, out int total, params SqlParameter[] cmdParms)
        {
            return dal.Gets(sqlWhere, pageindex, pagesize, out total, cmdParms);
        }
        #endregion  成员方法
    }
}


  